/***/
$(document).ready(function(){
/***************搜索按钮-显示搜索详情***********/
	var ctx=$("#inputCtx").val();
	$("#btnSubmit").click(function (){
		var bespeakNumber=$.trim($("#searchBespeakNumber").val());
		
		if(""!=bespeakNumber){
			 if(!(/^\d+$/.test(bespeakNumber))) {
				 layer.tips('请填写正确的预约数字', '#searchBespeakNumber', {
					  tips: [1, '#3595CC'],
					  time: 4000
					});
				 return false;
			 }
		}
		if((new String(bespeakNumber)).length!=11){
			layer.tips('请填写11位的预约编码', '#searchBespeakNumber', {
				  tips: [1, '#3595CC'],
				  time: 4000
				});
			return false;
		}
		if(222==checkbespeakStatus(bespeakNumber)){
			showBespeakDetail(bespeakNumber);
		}
		
	});


/***************确认预约***********/
	$("#makeAnAppointment").click(function (){
		var url=$("#inputCtx").val()+"/reservation/tdcReservation/make?BespeakNumber="+$("#searchBespeakNumberId").val();
		
		//iframe窗
		showSmallWindow('房间自动分配',url);		 
	});

});

	
/***************预约人信息详情展示-获取数据***********/
function showBespeakDetail(bespeakNumber){
	$("#showMsg01").css("display","block");
	if(""!=bespeakNumber){
		 if(!(/^\d+$/.test(bespeakNumber))) {
			 layer.tips('请填写正确的预约编码', '#searchBespeakNumber', {
				  tips: [1, '#3595CC'],
				  time: 4000
				});
			 
			 $("#showMsg01").css("display","none");
			 return "0";
//			 return false;
		 }
	}else {
		$("#showMsg01").css("display","none");
		return "0";
//		return false;
	}
	$.ajax({
		url:ctx+"/reservation/tdcReservation/search?bespeakNumber="+bespeakNumber,
//		url:ctx+"/visitor/search",
		type:"post",
//		data:"bespeakNumber="+bespeakNumber,
		data:{"bespeakNumber":bespeakNumber},
		contentType:"application/json",  
		async:false,
		success:function(data){ 
			var obj = eval("("+data+")");
//			律师姓名
//			var stmp="律师姓名:<c:out value='"+obj.bespeakName+"'></c:out>";
			var stmp=obj.bespeakNumber;
//			隐藏字段--预约编号
			$("#searchBespeakNumberId").val(stmp);
			stmp=obj.bespeakCredentials;
			$("#showDetail02").attr("src",stmp);
//			律师证件
			stmp=obj.bespeakCredentials;
			$("#showDetail02").attr("src",stmp);
//			嫌犯姓名
//			stmp="嫌犯姓名:<c:out value='"+obj.suspectName+"'></c:out>";
			stmp="嫌犯姓名:"+obj.suspectName;
			$("#showDetail03").html(stmp);
//			嫌犯附件证明
			stmp=obj.suspectAttachment;
			$("#showDetail04").attr("src",stmp);
//			嫌犯身份证号
			stmp=obj.suspectCredentialsNumber;
			$("#showDetail05").html(stmp);
//			预约时间
//			alert("obj.bespeakStart--"+obj.bespeakStart+"json2TimeStamp(obj.bespeakStart)--"+json2TimeStamp(obj.bespeakStart));			
//			stmp=json2TimeStamp(obj.bespeakStart)+"~"+json2TimeStamp(obj.bespeakEnd);
			stmp=(obj.bespeakStart.year+1900)+
				"-"+obj.bespeakStart.month+
				"-"+obj.bespeakStart.date+
				" "+obj.bespeakStart.hours+
				":"+obj.bespeakStart.minutes+
				"~"+obj.bespeakEnd.hours+
				":"+obj.bespeakEnd.minutes;
			$("#showDetail06").html(stmp);
			return "1";
		}
	});
}
/*************将json里的时间转换成正常格式****************/
function json2TimeStamp(milliseconds){
   var datetime = new Date();
   datetime.setTime(milliseconds);
   var year=datetime.getFullYear();
//        月份重0开始，所以要加1，当小于10月时，为了显示2位的月份，所以补0
   var month = datetime.getMonth() + 1 < 10 ? "0" + (datetime.getMonth() + 1) : datetime.getMonth() + 1;
   var date = datetime.getDate() < 10 ? "0" + datetime.getDate() : datetime.getDate();
   return year + "-" + month + "-" + date;
}
/*************预约人信息详情展示--弹层****************/
function showSmallWindow(titles,url){
/*	layer.open({
      type: 2,
      title: title,
      shadeClose: false,
      shade: 0.6,
//      scrollbar:0,
      maxmin: false, //开启最大化最小化按钮
      area: ['465px', '290px'],
      content: url
    });*/
	layer.open({
	  type: 2,
	  skin: 'layui-layer-demo', //样式类名
	  closeBtn: 1, //显示关闭按钮
	  anim: 2,
	  shadeClose: true, //开启遮罩关闭
	  area: ['465px', '290px'],
	  title: [titles, false],
	  content: url
	});
}
/**************** 验证预约状态********/
function checkbespeakStatus(bespeakNumber){
	
	var returnVal = 111;
	
	$.ajax({
		url:ctx+"/reservation/tdcReservation/findStatus",
		type:"post",
		data:"bespeakNumber="+bespeakNumber,
		async:false,
		success:function(data){
			if(data=="null"){
				layer.tips('该编号不存在！', '#searchBespeakNumber', {
				  tips: [1, '#3595CC'],
				  time: 4000
				});
			}else if(data=="NoNow"){
				layer.tips('预约时间不是今天！', '#searchBespeakNumber', {
					  tips: [1, '#3595CC'],
					  time: 4000
					});
			}else if(data=="false"){
				   layer.tips('用户已经确认预约成功！', '#searchBespeakNumber', {
						  tips: [1, '#3595CC'],
						  time: 4000
						}); 
			}else if(data=="noRoom"){
				layer.tips('房间已满！请更改房间状态！', '#searchBespeakNumber', {
					  tips: [1, '#3595CC'],
					  time: 4000
					});
			} else{
				returnVal = 222;
			}
		}
	});
	return returnVal;
}
	/*********获取详情**********/
function showBespeakDetails(bespeakNumber){
	$("#showMsg01").css("display","block");
	if(""!=bespeakNumber){
		 if(!(/^\d+$/.test(bespeakNumber))) {
			 layer.tips('请填写正确的预约编码', '#searchBespeakNumber', {
				  tips: [1, '#3595CC'],
				  time: 4000
				});
			 
			 $("#showMsg01").css("display","none");
			 return "0";
//			 return false;
		 }
	}else {
		$("#showMsg01").css("display","none");
		return "0";
//		return false;
	}

}